﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ZSZ.Core.Entities;

namespace ZSZ.EntityFramework.ModelConfig
{
    class UserConfig:EntityTypeConfiguration<UserEntity>
    {
        //public UserConfig()
        //{
        //    ToTable("T_Users");
        //    HasRequired(u => u.City).WithMany().HasForeignKey(u => u.CityId).WillCascadeOnDelete(false);
        //    Property(p => p.PasswordHash).IsRequired().HasMaxLength(100);
        //    Property(p => p.PasswordSalt).IsRequired().HasMaxLength(20);
        //    Property(p => p.PhoneNum).IsRequired().HasMaxLength(20).IsUnicode(false);
        //}

        public override void Map(EntityTypeBuilder<UserEntity> builder)
        {
            builder.ToTable("T_Users");
            builder.HasOne(u => u.City).WithMany().HasForeignKey(u => u.CityId).OnDelete(DeleteBehavior.ClientSetNull);
            builder.Property(p => p.PasswordHash).IsRequired().HasMaxLength(100);
            builder.Property(p => p.PasswordSalt).IsRequired().HasMaxLength(20);
            builder.Property(p => p.PhoneNum).IsRequired().HasMaxLength(20).IsUnicode(false);
        }
    }
}
